<?php
require_once("admin-header.php");
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
<title>Add a contest</title>

<?php
$description="";
if (isset($_POST['syear']))
{
	require_once("../include/check_post_key.php");
	
	$starttime=intval($_POST['syear'])."-".intval($_POST['smonth'])."-".intval($_POST['sday'])." ".intval($_POST['shour']).":".intval($_POST['sminute']).":00";
	$endtime=intval($_POST['eyear'])."-".intval($_POST['emonth'])."-".intval($_POST['eday'])." ".intval($_POST['ehour']).":".intval($_POST['eminute']).":00";
	$SRtime=intval($_POST['SRyear'])."-".intval($_POST['SRmonth'])."-".intval($_POST['SRday'])." ".intval($_POST['SRhour']).":".intval($_POST['SRminute']).":00";
	$ERtime=intval($_POST['ERyear'])."-".intval($_POST['ERmonth'])."-".intval($_POST['ERday'])." ".intval($_POST['ERhour']).":".intval($_POST['ERminute']).":00";
//	echo $starttime;
//	echo $endtime;
	$Ckind=$_POST['ckind'];
	$title=$_POST['title'];
	$description=$_POST['description'];
/*	if (get_magic_quotes_gpc ())
	{
		$title = stripslashes ($title);
		$description = stripslashes ($description);
	}*/
	$title=mysql_real_escape_string($title);
	$description=mysql_real_escape_string($description);
	$sql="INSERT INTO `bm_contest`(`bm_c_title`,`bm_c_start`,`bm_c_end`,`bm_c_startreg`,`bm_c_endreg`,`bm_c_kind`,`bm_c_description`)
		VALUES('$title','$starttime','$endtime','$SRtime','$ERtime','$Ckind','$description')";
//	echo $sql;
	mysql_query($sql) or die(mysql_error());
	$cid=mysql_insert_id();
	echo "Add Contest ".$cid;
	$_SESSION["m$cid"]=true;
	$pieces = explode("\n", trim($_POST['ulist']));
	echo "<script>window.location.href=\"contest_list.php\";</script>";
}
else
{
	if(isset($_GET['cid']))
	{
		$cid=intval($_GET['cid']);
		$sql="select * from bm_contest WHERE `bm_c_id`='$cid'";
		$result=mysql_query($sql) or die(mysql_error());
		$row=mysql_fetch_object($result);
		$title=$row->bm_c_title;
		mysql_free_result($result);
	}
	include_once("../fckeditor/fckeditor.php") ;
?>
	<form method=POST >
	<p align=center><font size=4 color=#333399>Add a Contest</font></p>
	<p align=left>Title:<input type=text name=title size=71 value="<?php echo isset($title)?$title:""?>"></p>
	<p align=left>Start Time:<br>&nbsp;&nbsp;&nbsp;
	Year:<input type=text name=syear value=<?php echo date('Y')?> size=4 >
	Month:<input type=text name=smonth value=<?php echo date('m')?> size=2 >
	Day:<input type=text name=sday size=2 value=<?php echo date('d')?> >&nbsp;
	Hour:<input type=text name=shour size=2 value=<?php echo date('H')?>>&nbsp;
	Minute:<input type=text name=sminute value=00 size=2 ></p>
    
	<p align=left>End Time:<br>&nbsp;&nbsp;&nbsp;
	Year:<input type=text name=eyear value=<?php echo date('Y')?> size=4 >
	Month:<input type=text name=emonth value=<?php echo date('m')?> size=2 >
	Day:<input type=text name=eday size=2 value=<?php echo date('d')+(date('H')+4>23?1:0)?>>&nbsp;
	Hour:<input type=text name=ehour size=2 value=<?php echo (date('H')+4)%24?>>&nbsp;
	Minute:<input type=text name=eminute value=00 size=2 ></p>
    
	<p align=left>Start Register Time:<br>&nbsp;&nbsp;&nbsp;
	Year:<input type=text name=SRyear value=<?php echo date('Y')?> size=4 >
	Month:<input type=text name=SRmonth value=<?php echo date('m')?> size=2 >
	Day:<input type=text name=SRday size=2 value=<?php echo date('d')+(date('H')+4>23?1:0)?>>&nbsp;
	Hour:<input type=text name=SRhour size=2 value=<?php echo date('H')?>>&nbsp;
	Minute:<input type=text name=SRminute value=00 size=2 ></p>
    
	<p align=left>End Register Time:<br>&nbsp;&nbsp;&nbsp;
	Year:<input type=text name=ERyear value=<?php echo date('Y')?> size=4 >
	Month:<input type=text name=ERmonth value=<?php echo date('m')?> size=2 >
	Day:<input type=text name=ERday size=2 value=<?php echo date('d')+(date('H')+4>23?1:0)?>>&nbsp;
	Hour:<input type=text name=ERhour size=2 value=<?php echo (date('H')+4)%24?>>&nbsp;
	Minute:<input type=text name=ERminute value=00 size=2 ></p>
    
	Kind:<select name=ckind><option value=0>组队赛</option><option value=1>个人赛</option></select>
	<?php require_once("../include/set_post_key.php");?>
	<br/>
	<p align=left>Description:<br/><!--<textarea rows=13 name=description cols=80></textarea>-->

<?php
$fck_description = new FCKeditor('description') ;
$fck_description->BasePath = '../fckeditor/' ;
$fck_description->Height = 300 ;
$fck_description->Width=600;
$fck_description->Value = $description ;
$fck_description->Create() ;

?>
<p><input type=submit value=Submit name=submit><input type=reset value=Reset name=reset></p>
</form>
<?php }
require_once("../bm-footer.php");

?>

